package com.smasher.widget.selection;

import android.content.Context;

import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
import com.bigkoo.pickerview.view.OptionsPickerView;
import com.smasher.widget.R;

import java.util.List;

public class OptionSelection {

    private final String mTitle;
    private int mConfirmText;
    private int mCancelText;

    private final OnOptionsSelectListener mOnOptionsSelectListener;

    public OptionSelection(OptionBuilder optionBuilder) {
        mTitle = optionBuilder.getTitle();
        mConfirmText = optionBuilder.getConfirmText();
        mCancelText = optionBuilder.getCancelText();
        mOnOptionsSelectListener = optionBuilder.getOnOptionsSelectListener();
        if (mConfirmText == 0) {
            mConfirmText = R.string.app_ok;
        }
        if (mCancelText == 0) {
            mCancelText = R.string.app_cancel;
        }

    }

    public <T> void showOptions(Context context, List<T> options) {
        OptionsPickerView<T> areaPickerView = new OptionsPickerBuilder(context, mOnOptionsSelectListener)
                .setTitleText(mTitle)
                .setSubmitText(context.getString(mConfirmText))
                .setCancelText(context.getString(mCancelText))
                .build();
        areaPickerView.setPicker(options);
        areaPickerView.show();
    }
}
